
#include <QtCore/QCoreApplication>
#include <QTcpServer>
#include <QTcpSocket>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTcpServer server;
    server.listen(QHostAddress::Any, 80);

    QObject::connect(&server, &QTcpServer::newConnection, [&]()
    {
        cout << "New Connection!" << endl;
        QTcpSocket *socket = server.nextPendingConnection();

        socket->write("Welcome to test server!");

        QObject::connect(socket, &QTcpSocket::readyRead, [&]()
        {
            cout << "New Data!" << endl;
            auto data = socket->readAll();
            socket->write(data);
        });
    });



    return a.exec();
}
